from selenium import webdriver
from pprint import pprint


class Cookie:
    def __init__(self):
        # 打开浏览器请求网址
        self.driver = webdriver.Chrome()
        self.driver.get('https:/www.baidu.com')

        # 获取所有cookie信息
        pprint(self.driver.get_cookies())

        # 返回特定name的cookie信息
        pprint(self.driver.get_cookie('BA_HECTOR'))

        # 添加cookie，必须有name和value值
        # 准备cookie[字典]
        dict = {'name': 'hello', 'value': '123'}
        self.driver.add_cookie(dict)
        pprint(self.driver.get_cookies())

        # 删除特定部分的cookie信息
        self.driver.delete_cookie('hello')
        pprint(self.driver.get_cookies())

        # 清空所有cookie信息
        self.driver.delete_all_cookies()
        pprint(self.driver.get_cookies())


    def quit(self):
        self.driver.quit()

if __name__ == '__main__':
    pass
